def jwt_response_payload_handler(token, user=None, request=None):
    """
    自定义jwt认证成功返回数据
    """
    return {
        'token': token,
        'id': user.id,
        'username': user.username
    }



# 自定义多条件验证
from django.contrib.auth.backends import ModelBackend
from django.db.models import Q
from .models import User


class UserMobileAuthBackend(ModelBackend):

    def authenticate(self, request, username=None, password=None, **kwargs):
        try:
            user = User.objects.get(Q(username=username) | Q(mobile=username))
        except User.DoesNotExist:
            user = None
            return user

        if user and user.check_password(password) and user.is_active:
            return user
